<?php
class my_library
{
function daysDifference($endDate, $beginDate)
{

   //explode the date by "-" and storing to array
   $date_parts1=explode("-", $beginDate);
   $date_parts2=explode("-", $endDate);

   /* //gregoriantojd() Converts a Gregorian date to Julian Day Count
   $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
   //die($date_parts2[1].'x'.$date_parts2[2].'x'.$date_parts2[0]);
   $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
   return $end_date - $start_date;*/

   //gregoriantojd() Converts a Gregorian date to Julian Day Count
   $start_date=gregoriantojd($date_parts1['1'], $date_parts1['2'], $date_parts1['0']);
   //die($date_parts2[1].'x'.$date_parts2[2].'x'.$date_parts2[0]);
   $end_date=gregoriantojd($date_parts2['1'], $date_parts2['2'], $date_parts2['0']);
   $answer = $end_date - $start_date;
   return $answer;
}
function updateCurrentTrackingValue($veh_id, $new_value)
{
 $result_old = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$veh_id."'")
 or die("SELECT OLD ".mysql_error());
 $row_old = mysql_fetch_array($result_old);
 $tracking = $row_old['track_by'];

 if($tracking=='distance')
 {
 $old_tracking_value = $row_old['curr_tracking_value'];
 $save_here = 'curr_tracking_value';
 }

 if($tracking=='hours')
 {
 $old_tracking_value = $row_old['curr_hours'];
 $save_here = 'curr_hours';
 }

 if($old_tracking_value<$new_value)
 mysql_query("UPDATE vehicle_tbl SET ".$save_here."='".$new_value."'
 WHERE vehicle_id='".$veh_id."'")
 or die("UPDATE CURRENT TRACKING ".mysql_error());
}
}